Skip to content

Conversation

@0xMink
Copy link
Contributor

@0xMink 0xMink commented Feb 8, 2026

Closes: #11311

Summary

  • Idempotent dispose(): Added _disposed guard so repeated calls (e.g. during rapid extension deactivation) are no-ops.
  • Catch postMessageToWebview() rejections: Wrapped webview.postMessage() in try/catch so messages sent after the webview is disposed do not surface as unhandled promise rejections.
  • Tests + mock maintenance: Two new tests covering both fixes. Updated the CloudService mock to include off() — a pre-existing gap exposed by the new dispose test.

Test plan

  • postMessageToWebview does not throw when webview is disposed
  • dispose() is idempotent — second call is a no-op
  • All 90 existing tests still pass (6 skipped, unchanged)

Roadmap alignment: Reliability First


Important

Make dispose() idempotent and handle promise rejections in postMessageToWebview() in ClineProvider to improve reliability.

  • Behavior:
    • Make dispose() in ClineProvider idempotent by adding _disposed flag to prevent repeated execution.
    • Wrap postMessageToWebview() in ClineProvider with try/catch to handle promise rejections when webview is disposed.
  • Tests:
    • Add test for postMessageToWebview to ensure no error is thrown when webview is disposed.
    • Add test for dispose() to verify it is idempotent and logs only once.
  • Mocks:
    • Update CloudService mock to include off() method in ClineProvider.spec.ts.

This description was created by Ellipsis for e0808ae. You can customize this summary. It will automatically update as commits are pushed.

…e idempotent

Closes: RooCodeInc#11311

1. postMessageToWebview() now catches rejections from
   webview.postMessage() so that messages sent after the webview is
   disposed do not surface as unhandled promise rejections.

2. dispose() is guarded by a _disposed flag so that repeated calls
   (e.g. during rapid extension deactivation) are no-ops.

3. CloudService mock in ClineProvider.spec.ts updated to include
   off() — a pre-existing gap exposed by the new dispose test.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Feb 8, 2026
@roomote
Copy link
Contributor

roomote bot commented Feb 8, 2026

Rooviewer Clock   See task

Re-reviewed the latest commits (e0808ae...948069c). The added _disposed early-return in postMessageToWebview() and accompanying test are clean. No new issues.

  • No issues to resolve
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-scoped PR. The idempotent dispose guard and the postMessage try/catch are both correct and well-tested.

Minor observations (non-blocking):

  1. Bare catch {} in postMessageToWebview — This silently swallows all errors, not just "webview is disposed" ones. In practice the only thing webview.postMessage() can throw is a disposed-webview error, so this is fine. If you wanted to be defensive you could log at debug level, but it's not necessary.

  2. _disposed not checked in postMessageToWebview — After dispose() runs, this.view is disposed but not nulled out, so postMessageToWebview still attempts the call and relies on the try/catch. An early if (this._disposed) return would avoid the unnecessary call entirely, but the try/catch is the more robust approach since it also handles external disposal (VS Code closing the webview independently). So the current approach is arguably better.

  3. Mock fix — Adding off: vi.fn() to the CloudService mock is a legitimate gap fix, good catch.

LGTM ✅

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 9, 2026
Skip the postMessage call entirely when the provider is already disposed,
avoiding unnecessary try/catch execution. Added test coverage for this path.
@daniel-lxs daniel-lxs merged commit 62a0106 into RooCodeInc:main Feb 9, 2026
10 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] postMessageToWebview unhandled rejection; dispose() not idempotent

2 participants